subroutine calcene2(t1, t2, fia, iabij, eccsd)
use mod_iop
use mod_size
use mod_orbit
use mod_ioff 
implicit none
real*8, intent(inout) :: eccsd
real*8, intent(in) :: t1(*), t2(*), fia(*), iabij(*) 
!
if(prec==8.and.igpu==0) then 
   call calcene2_d(t1, t2, fia, iabij, eccsd)
elseif(prec==4.and.igpu==0) then 
   call calcene2_s(t1, t2, fia, iabij, eccsd)
elseif(prec==8.and.igpu==1) then 
   call calcene2_dg(t1, t2, fia, iabij, eccsd)
elseif(prec==4.and.igpu==1) then 
   call calcene2_sg(t1, t2, fia, iabij, eccsd)
endif
!
return
end

subroutine calcene2_d(t1, t2, fia, iabij, eccsd)
use mod_iop
use mod_size
use mod_orbit
use mod_ioff 
!use common
implicit none
real*8, intent(inout) :: eccsd
real*8, intent(in) :: t1(*), t2(*), fia(*), iabij(*)
!
real*8 :: eso
real*8, external :: ddot
integer :: i
!
eso = ddot(nifvo, t1, 1, fia, 1)
eccsd=0.d0
!$omp parallel do reduction(+:eccsd)
do i = 1, nioi3 
   eccsd = eccsd + t2(i)*iabij(i)
enddo
!$omp end parallel do
   eccsd = eccsd-eso
!
return
end
!
subroutine calcene2_s(t1, t2, fia, iabij, eccsd)
use mod_iop
use mod_size
use mod_orbit
use mod_ioff 
!use common
implicit none
real*8, intent(inout) :: eccsd
real*4, intent(in) :: t1(*), t2(*), fia(*), iabij(*) 
!
real*8 :: eso
real*4, external :: sdot
integer i
!
!eso = sdot(nifvo, t1, 1, fia, 1)
eso = 0.d0 
!$omp parallel do reduction(+:eso)
do i = 1, nifvo 
   eso = eso + t1(i)*fia(i)
enddo
!$omp end parallel do
eccsd=0.d0
!$omp parallel do reduction(+:eccsd)
do i = 1, nioi3 
   eccsd = eccsd + t2(i)*iabij(i)
enddo
!$omp end parallel do
eccsd = eccsd + eso
!
return
end
!
subroutine calcene2_dg(t1, t2, fia, iabij, eccsd)
use mod_iop
use mod_size
use mod_orbit
use mod_ioff 
!use common
implicit none
real*8, intent(inout) :: eccsd
real*8, intent(in),device :: t1(*), t2(*), fia(*), iabij(*)
!
real*8 :: eso
integer i
!
eccsd=0.d0
!$acc parallel loop reduction(+:eccsd)
do i = 1, nioi3
   eccsd = eccsd + t2(i)*iabij(i)
enddo
!$acc end parallel loop
!
return
end
!
subroutine calcene2_sg(t1, t2, fia, iabij, eccsd)
use mod_iop
use mod_size
use mod_orbit
use mod_ioff 
!use common
implicit none
real*8, intent(inout) :: eccsd
real*4, intent(in),device :: t1(*), t2(*), fia(*), iabij(*)
!
real*8 :: eso
real*4, external :: sdot
integer i
!
eccsd=0.d0
!$acc parallel loop reduction(+:eccsd)
do i = 1, nioi3
   eccsd = eccsd + t2(i)*iabij(i)
enddo
!$acc end parallel loop
!
return
end
